/**

This file is part of MaCI/GIMnet.

MaCI/GIMnet is free software: you can redistribute it and/or modify it 
under the terms of the GNU Lesser General Public License as published 
by the Free Software Foundation, either version 3 of the License, or 
(at your option) any later version.

MaCI/GIMnet is distributed in the hope that it will be useful, but WITHOUT 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public 
License for more details.

You should have received a copy of the GNU Lesser General Public 
License along with GIMnet. (See COPYING.LESSER) If not, see 
<http://www.gnu.org/licenses/>.

**/
#ifndef _OCCU_GUI_H_
#define _OCCU_GUI_H_

#include <SDL/SDL.h>
#include <SDL/SDL_gfxPrimitives.h>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <math.h>
#include <time.h>
#include <unistd.h>

#include "TOccupancyGrid.h"
#include "EnvironmentMeasurement2D.h"
#include "MatchStorage.h"
#include "JPEGEncoder.hpp"

class COccuGUI{
	public:
		COccuGUI(const char *mapfile,float resolution, float scale = 1.0);
		COccuGUI(float size,float resolution, float scale = 1.0);
		
		void setOccupancyGrid(	TOccupancyGrid *gr);
		
		TOccupancyGrid *grid;
		
		bool drawGrid();
		
		bool generateMeasurement(CEnvironmentMeasurement2D &meas);
		bool generateOccuMeasurement(CEnvironmentMeasurement2D &meas,float local_occu_size=30.0);
		bool plotMatchResults(CMatchStorage &result, float x, float y, float a,float variance=0.15);
		bool plotMatchResultsWithPoints(CMatchStorage &result, CEnvironmentMeasurement2D &meas, 
																							float x, float y, float a,float variance=0.15);
		
		bool plotEnvironmentMeasurement2D(CEnvironmentMeasurement2D &meas);
		void save();
		
	private:
		SDL_Surface *screen;
		float scale; ///scale between the map and output picture
		bool initSDL();
		bool cleanSDL();
		void printGeneralInfo();
		/**
		 * Plots the map using scaling
		 **/
		void plotMap();
		///Converts scaled screen pixel to map pixel
		void screenToMapPixel(Grid::TPixel &pix);
		void mapToScreenPixel(Grid::TPixel &pix);

};

#endif
